package com.diaohw.module.websocket.obj.vo;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.IdUtil;
import com.diaohw.module.websocket.obj.enums.WSStatusEnums;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@Schema(description = "消息返回")
public class MsgVO implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    private String id;

    private String data;

    private WSStatusEnums type;

    private String topic;

    private String subscribeId;

    private boolean status;

    private String token;

    @JsonFormat(pattern = DatePattern.NORM_DATETIME_MS_PATTERN)
    private LocalDateTime sendTime;

    public static MsgVO of(String data, WSStatusEnums type, String topic, String subscribeId, boolean status) {
        MsgVO vo = new MsgVO();
        vo.setData(data);
        vo.setType(type);
        vo.setTopic(topic);
        vo.setSubscribeId(subscribeId);
        vo.setStatus(status);
        vo.setSendTime(LocalDateTime.now());
        vo.setId(IdUtil.simpleUUID());
        return vo;
    }

    public static MsgVO of(String data, WSStatusEnums type, String topic, String subscribeId, boolean status, String token) {
        MsgVO msgVO = of(data, type, topic, subscribeId, status);
        msgVO.setToken(token);
        return msgVO;
    }
}
